/*
 * @lc app=leetcode.cn id=844 lang=typescript
 *
 * [844] 比较含退格的字符串
 */

// @lc code=start

// 倒序法更优 但是步骤麻烦，代码众多
function backspaceCompare(s: string, t: string): boolean {
    // 暴力法
    const getLast = (s: string) => {
        return s
            .split("")
            .reduce((col, cur) => {
                if (cur === "#") {
                    col.pop();
                } else {
                    col.push(cur);
                }

                return col;
            }, [] as string[])
            .join("");
    };
    const s_copy = getLast(s);
    const t_copy = getLast(t);
    return s_copy === t_copy;
}
// @lc code=end
